package com.hippo.core.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.hippo.core.R
import com.hippo.core.core.ext.click
import com.hippo.core.ui.theme.ColorTextBlack
import com.hippo.core.ui.theme.HippoTheme

@Composable
fun TextLayout(
    modifier: Modifier = Modifier,
    text: String,
    leftPainter: Painter? = null,
    rightPainter: Painter? = painterResource(id = R.mipmap.arrow_right),
    onRightClick: (() -> Unit)? = null,
    onClick: (() -> Unit)? = null,
) {

    Row(
        modifier = modifier,
        verticalAlignment = Alignment.CenterVertically,
    ) {

        if (leftPainter != null) {
            Image(
                modifier = Modifier
                    .padding(5.dp)
                    .size(18.dp),
                painter = leftPainter,
                contentDescription = null,
            )
        }
        Column {

            Row(
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier
                    .padding(vertical = 16.dp, horizontal = 8.dp)
                    .click { onClick?.invoke() },
            ) {

                Text(
                    text = text,
                    modifier = Modifier.weight(1f),
                    fontSize = 16.sp,
                    color = ColorTextBlack
                )

                if (rightPainter != null) {
                    Image(
                        painter = rightPainter,
                        contentDescription = null,
                        modifier = Modifier.size(25.dp)
                    )
                }
            }

            HorizontalDivider(thickness = 0.5.dp)
        }

    }

}


@Preview(showBackground = true)
@Composable
private fun ItemLayoutPreview() {
    HippoTheme {
        TextLayout(
            leftPainter = painterResource(id = R.mipmap.mine_setting),
            text = "Item Layout",
        )
    }
}

